//
//  BusinessViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 15/9/8.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//

#import "ServiceViewController.h"
#import "RDVTabBarController.h"
#import "RDVTabBarItem.h"
#import "ServiceView.h"
#import "peisongBiaoqianModel.h"
#import "peisongCell.h"
#import "HttpRequest.h"
#import "UIButton+WebCache.h"
#import "HAODEsingleton.h"

#import "TheLoginViewController.h"
#import "huiyuandengjiViewController.h"
#import "GetProductListViewController.h"
#import "GenerateQRCodeViewController.h"
#import "ScanViewController.h"
#import "ShopcatListViewController.h"
#import "MJRefresh.h"
#import "EstateFeeListViewController.h"
#import "NoticeListViewController.h"
#import "DemandRepairListViewController.h"
#import "ProposalListViewController.h"
#import "ConvenienceListViewController.h"
#import "financeListViewController.h"
#import "foodListViewController.h"
#import "handyListViewController.h"
#import "ConvenienceDetailViewController.h"
#import <CoreLocation/CoreLocation.h>
#import "SelectTheCertificationViewController.h"
#import <CoreLocation/CLLocationManagerDelegate.h>
@interface ServiceViewController ()<UIGestureRecognizerDelegate,UINavigationControllerDelegate,CLLocationManagerDelegate,UIAlertViewDelegate>
@property (nonatomic, unsafe_unretained) NSInteger currentIndex;
@property(nonatomic ,strong)NSDictionary*myDic;
@property (strong, nonatomic) CLLocationManager *locManager;

@property (strong, nonatomic) NSString *currentLatitude; //纬度
@property (strong, nonatomic) NSString *currentLongitude; //经度
@property (nonatomic, strong) CLLocationManager *locationManager;
@end

@implementation ServiceViewController
{
    HAODEsingleton *commdity;
    ServiceView *mainScorllView;
    UIScrollView*mainScroll;
    UIScrollView*mainScroll1;
    NSMutableArray *ImageUrl1;
    NSMutableArray*LinkType;
    NSMutableArray*LinkCode;
    NSTimer *timess;
    UILabel*gonggao;
    NSArray*gonggaoarry;
    NSMutableArray *selectArray;//选择的
    NSMutableArray *Array;//选择的
    MJRefreshHeaderView* _header;
    MJRefreshFooterView* _footer;
    UIView*addView;
    BOOL saveAccount;
    NSMutableArray*title;
    NSMutableArray*phone;
    NSMutableArray*linkman;
    NSMutableArray*fid;
    NSMutableArray*intro;
    NSMutableArray*imageUrl;
    NSMutableArray*distance;
    NSMutableArray *allComment;
    NSMutableArray *ctype;
    NSString *result;
    int pageNumber;
    NSString* userAudit;
        // 定位服务对象 这个对象主要是取得当前的经纬度
  
        
   
}
@synthesize alt = alt;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"服务";
        
        
    }
    return self;
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    // 禁用 iOS7 返回手势
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    self.navigationController.delegate = nil;
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    saveAccount=YES;
    
    self.navigationController.navigationBarHidden=NO;
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    self.navigationController.delegate = self;
       [[self rdv_tabBarController] setTabBarHidden:NO];
    
    
    UIImage* backImage = [UIImage imageNamed:@""];
    CGRect backframe = CGRectMake(0,0,34/3,62/3);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
 
    
    
    
    self.title = @"服务";
    if ([[[UIDevice currentDevice] systemVersion] doubleValue] > 8.0)
    {
        //设置定位权限 仅ios8有意义
        [self.locationManager requestWhenInUseAuthorization];// 前台定位
        
        //  [locationManager requestAlwaysAuthorization];// 前后台同时定位
    }
    
    [self.locManager startUpdatingLocation];
    
    _locManager = [[CLLocationManager alloc] init];
    
    _locManager.delegate = self;
    
    _locManager.desiredAccuracy = kCLLocationAccuracyBest;
    
    _locManager.distanceFilter = 1.0f;
    
    
    NSLog(@"%f",_locManager.location.coordinate.longitude);
    NSLog(@"%f",_locManager.location.coordinate.latitude);
    
    
    
    commdity. latitude=[NSString stringWithFormat:@"%f",  _locManager.location.coordinate.latitude];
    
    commdity. longitude=[NSString stringWithFormat:@"%f",_locManager.location.coordinate.longitude];
    
}




- (CLLocationManager *)locationManager{
    if(!_locationManager){
        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.delegate = self;
    }
    return _locationManager;
}



- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.title = @"";
    commdity=[HAODEsingleton shared];
   
    gonggaoarry=[[NSArray alloc]init];
  
    
    commdity =[HAODEsingleton shared];
    
    _table.delegate=self;
    _table.dataSource=self;
    _table.separatorStyle=UITableViewCellSeparatorStyleNone;

   [_table registerNib:[UINib nibWithNibName:@"peisongCell" bundle:nil] forCellReuseIdentifier:@"peisongCell"];


    [self addheader];

   
    
    
    
    mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth,460-110)];
    mainScroll.delegate = self;
    mainScroll.userInteractionEnabled = YES;
    mainScroll.scrollEnabled = YES;
    mainScroll.showsVerticalScrollIndicator = FALSE;
    mainScroll.showsHorizontalScrollIndicator = FALSE;
    
    self.table .tableHeaderView=mainScroll;
    UIImageView *line11 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
    line11.backgroundColor = zuiqianhuicolor;
    [mainScroll addSubview:line11];
    
    //热门面料
    CGFloat bottom = [self _initWithframe:CGRectMake(0,10, ScreenWidth, 1) title:@"物业服务"];
    
    
    UIScrollView *scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, bottom+20, ScreenWidth, 100)];
    scroll.bounces = NO;
    [mainScroll addSubview:scroll];
    
    NSArray*nameBtn=[[NSArray alloc]initWithObjects:@"物业通告",@"物业费",@"报修",@"投诉",nil];
     NSArray *arrayimage = @[@"wuyetonggao",@"wuyefei",@"baoxiu",@"tousu"];
    for (int i = 0; i<4; i++) {
        UIButton *nameButcenter = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/4*i,   bottom+15, ScreenWidth/4, 45)];
  
        [mainScroll addSubview:nameButcenter];
        UIButton *nameBut = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/4*i,   bottom+70, ScreenWidth/4, 14)];
        [nameBut setTitle: [nameBtn objectAtIndex:i]  forState:UIControlStateNormal];
        nameBut.tag=201+i;
        [nameBut setTitleColor:shenhuicolor forState:0];
        nameBut.titleLabel.font=[UIFont systemFontOfSize:14];
        [nameBut addTarget:self action:@selector(wuyebuttonimage:) forControlEvents:UIControlEventTouchUpInside];
        
        [mainScroll addSubview:nameBut];
        UIButton *wuyebuttonimage = [UIButton buttonWithType:UIButtonTypeCustom];
        wuyebuttonimage.frame = CGRectMake(ScreenWidth/4*i,   bottom+10, 45, 45);
        
        wuyebuttonimage.tag = 201+i;
        wuyebuttonimage.center=nameButcenter.center;
        [wuyebuttonimage setImage:[UIImage imageNamed: [arrayimage objectAtIndex:i]] forState:UIControlStateNormal];
        [wuyebuttonimage addTarget:self action:@selector(wuyebuttonimage:) forControlEvents:UIControlEventTouchUpInside];
        [mainScroll addSubview:wuyebuttonimage];
    }
    


    UIImageView *line1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 90, ScreenWidth, 10)];
    line1.backgroundColor = zuiqianhuicolor;
    [scroll addSubview:line1];
    
    //最新面料
    CGFloat bottom2 = [self _initWithframe:CGRectMake(0,scroll.bottom+10, ScreenWidth, 1) title:@"商户服务"];
    UIScrollView *scroll2 = [[UIScrollView alloc]initWithFrame:CGRectMake(0, bottom2+10, ScreenWidth, 100)];
    scroll2.bounces = NO;
    [mainScroll addSubview:scroll2];
    
        //优质商家
    CGFloat bottom3 = [self _initWithframe:CGRectMake(0, scroll2.bottom+10, ScreenWidth, 1) title:@"为您推荐"];
    
    UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(15,460-110-0.5, ScreenWidth-30, 0.5)];
    _xianview.image=[UIImage imageNamed:@"hengxian"];
    [mainScroll addSubview:_xianview];

    
    
    
        NSArray *array = @[@"提货配送",@"金额信贷",@"美食外卖",@"便民服务"];
        NSArray *arrayimage1 = @[@"wuliupeisong",@"jinrongxindai",@"meishiwaimai",@"bianminfuwu"];
        for (int i = 0; i<4; i++) {
            
            
            UIButton *nameButcenter = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/4*i,   bottom2+15, ScreenWidth/4, 45)];
            
            [mainScroll addSubview:nameButcenter];
            UIButton *shanghubutton = [UIButton buttonWithType:UIButtonTypeCustom];
            shanghubutton.frame = CGRectMake(ScreenWidth/4*i,   bottom2+70, ScreenWidth/4, 14);

            shanghubutton.tag = 301+i;
            [shanghubutton setTitle:[array objectAtIndex:i] forState:UIControlStateNormal];
            [shanghubutton setTitleColor:shenhuicolor forState:UIControlStateNormal];
             shanghubutton.titleLabel.font=[UIFont systemFontOfSize:14];
            [shanghubutton addTarget:self action:@selector(shanghubuttonimage:) forControlEvents:UIControlEventTouchUpInside];
            [mainScroll addSubview:shanghubutton];
            
            
           
            UIButton *shanghubuttonimage = [UIButton buttonWithType:UIButtonTypeCustom];
            shanghubuttonimage.frame = CGRectMake(ScreenWidth/4*i,   bottom2+10, 45, 45);
            
            shanghubuttonimage.tag = 301+i;
            shanghubuttonimage.center=nameButcenter.center;
            [shanghubuttonimage setImage:[UIImage imageNamed: [arrayimage1 objectAtIndex:i]] forState:UIControlStateNormal];
            [shanghubuttonimage addTarget:self action:@selector(shanghubuttonimage:) forControlEvents:UIControlEventTouchUpInside];
            [mainScroll addSubview:shanghubuttonimage];

            
            
            
        }
    
    
    UIImageView *line = [[UIImageView alloc]initWithFrame:CGRectMake(0, 90, ScreenWidth, 10)];
    line.backgroundColor = zuiqianhuicolor;
    [scroll2 addSubview:line];
    
    
    [self add];
    
    
}

    
    
   
    
-(void)add{
        
        
    if ([[[UIDevice currentDevice] systemVersion] doubleValue] > 8.0)
    {
        //设置定位权限 仅ios8有意义
        [self.locationManager requestWhenInUseAuthorization];// 前台定位
        
        //  [locationManager requestAlwaysAuthorization];// 前后台同时定位
    }
    
    [self.locManager startUpdatingLocation];
    
    _locManager = [[CLLocationManager alloc] init];
    
    _locManager.delegate = self;
    
    _locManager.desiredAccuracy = kCLLocationAccuracyBest;
    
    _locManager.distanceFilter = 1.0f;
    
    
    NSLog(@"%f",_locManager.location.coordinate.longitude);
    NSLog(@"%f",_locManager.location.coordinate.latitude);
    
    
    
    commdity. latitude=[NSString stringWithFormat:@"%f",  _locManager.location.coordinate.latitude];
    
    commdity. longitude=[NSString stringWithFormat:@"%f",_locManager.location.coordinate.longitude];

    
        
        pageNumber = 1;
        
        
        fid= [[NSMutableArray alloc] init];
        imageUrl= [[NSMutableArray alloc] init];
        
        phone = [[NSMutableArray alloc] init];
        linkman = [[NSMutableArray alloc] init];
        intro = [[NSMutableArray alloc] init];
        title = [[NSMutableArray alloc] init];
        distance = [[NSMutableArray alloc] init];
        ctype= [[NSMutableArray alloc] init];
        
    
        
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString* Token = [user objectForKey:@"tokenId"];
        if (Token ==nil) {
            Token=@"dd";
        }
        NSMutableDictionary *param = [NSMutableDictionary new];
        [param setValue:Token forKey:@"tokenId"];
        [param setValue:@"1" forKey:@"pageIndex"];
        [param setValue:@"20" forKey:@"pageSize"];
    
    [param setValue:commdity.longitude forKey:@"longitude"];
    [param setValue:commdity.latitude forKey:@"latitude"];
NSLog(@"====%@",param);
        [HttpRequest requestData:@"/Convenience/Hot" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                
                NSLog(@"====%@",severDataDict.dataDict);
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    
                    NSMutableArray* arrr=[[NSMutableArray alloc]init];
                    NSString*TotalCount=[severDataDict.dataDict objectForKey:@"TotalCount"];
                    arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                    [self setupCouponCommentView:severDataDict.dataDict];
                    if (TotalCount.intValue==0) {

                        
                    }else{
                        
                        
                        for (NSDictionary* dicc in arrr )
                        {
                          [ctype addObject:[dicc valueForKey:@"ctype"]];

                            [title addObject:[dicc valueForKey:@"title"]];
                            [phone addObject:[dicc valueForKey:@"phone"]];
                            [linkman addObject:[dicc valueForKey:@"linkman"]];
                            [fid addObject:[dicc valueForKey:@"fid"]];
                            [intro addObject:[dicc valueForKey:@"intro"]];
                            [imageUrl addObject:[dicc valueForKey:@"imageUrl"]];
                            
                            [distance addObject:[dicc valueForKey:@"distance"]];
                        }
                        
                    }
                    [_table reloadData];
                    
                    
                    
                    
                }else{
                    [Global hideProgressHUDInternal:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                        
                        TheLoginViewController *detailViewController = [[TheLoginViewController alloc] init];
                        [self.navigationController pushViewController:detailViewController animated:YES];
                    }
                    
                }
                
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
            
        }];
        
        
        
        
    }

- (CGFloat)_initWithframe:(CGRect )frame title:(NSString *)titles {
    //线
    UIImageView *line = [[UIImageView alloc]initWithFrame:frame];
    line.backgroundColor = [UIColor clearColor];
    [mainScroll addSubview:line];
    //蓝色小点
    
     UILabel *quan = [[UILabel alloc]initWithFrame:CGRectMake(10, line.bottom+9, 15, 15)];
    quan.textColor = luseColor;
    quan.text=@"o";
    quan.font=[UIFont boldSystemFontOfSize:15];
    [mainScroll addSubview:quan];
   
    
    UILabel *label_title = [[UILabel alloc]initWithFrame:CGRectMake(25, line.bottom+10, 80, 15)];
    label_title.text = titles;
    label_title.font=[UIFont systemFontOfSize:15];
    [mainScroll addSubview:label_title];
    return label_title.bottom;
}




-(void)renzhensat{
    
    if ([userAudit isEqualToString:@"E"]) {
        SelectTheCertificationViewController * Login=[[SelectTheCertificationViewController alloc]init];
        
        [self.navigationController pushViewController:Login animated:YES];
    }
    if ([userAudit isEqualToString:@"N"]) {
        SelectTheCertificationViewController * Login=[[SelectTheCertificationViewController alloc]init];
        
        [self.navigationController pushViewController:Login animated:YES];
    }
    if ([userAudit isEqualToString:@"W"]) {
        [self showAlertMessage:@"账号信息审核中，请耐心等待"];
    }
    
    
}


- (void)wuyebuttonimage:(UIButton *)button{
    
    
    if (button.tag==201) {
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        
         userAudit = [user objectForKey:@"userAudit"];
        
        if ([userAudit isEqualToString:@"Y"]) {
            
            
            NoticeListViewController* store=[[NoticeListViewController alloc]init];
            
            [self.navigationController pushViewController:store animated:YES];
            
        }else{
           [self renzhensat];
        }

       
        

        
        
    }
    if (button.tag==202) {
        
        
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        
       userAudit = [user objectForKey:@"userAudit"];
        
        if ([userAudit isEqualToString:@"Y"]) {
            
            EstateFeeListViewController* store=[[EstateFeeListViewController alloc]init];
            
            [self.navigationController pushViewController:store animated:YES];

        }else{
            [self renzhensat];
        }
        


        
    }

    if (button.tag==203) {
        
        
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        
        userAudit = [user objectForKey:@"userAudit"];
        
        if ([userAudit isEqualToString:@"Y"]) {
            
            DemandRepairListViewController* store=[[DemandRepairListViewController alloc]init];
            
            [self.navigationController pushViewController:store animated:YES];
        }else{
            [self renzhensat];
        }
        

        
        
        
    }

        
   

    if (button.tag==204) {
     
       
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        
         userAudit = [user objectForKey:@"userAudit"];
        
        if ([userAudit isEqualToString:@"Y"]) {
            
            ProposalListViewController* store=[[ProposalListViewController alloc]init];
            
            
            [self.navigationController pushViewController:store animated:YES];        }else{
                [self renzhensat];
            }
        

        
        
        
    }

}


- (void)shanghubuttonimage:(UIButton *)button{
    if (button.tag==301) {
        
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        
        userAudit = [user objectForKey:@"userAudit"];
        
//        if ([userAudit isEqualToString:@"Y"]) {
        
            ConvenienceListViewController* store=[[ConvenienceListViewController alloc]init];
            
            [self.navigationController pushViewController:store animated:YES];
//        }
        

        
       
        
    }
    if (button.tag==302) {
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        
      userAudit = [user objectForKey:@"userAudit"];
        
//        if ([userAudit isEqualToString:@"Y"]) {
            financeListViewController* store=[[financeListViewController alloc]init];
            
            [self.navigationController pushViewController:store animated:YES];
//        }

        
        

        
        
    }
    
    if (button.tag==303) {
        
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        
       userAudit = [user objectForKey:@"userAudit"];
        
//        if ([userAudit isEqualToString:@"Y"]) {
            foodListViewController* store=[[foodListViewController alloc]init];
            
            [self.navigationController pushViewController:store animated:YES];
//        }

        
       

        
    }
    
    if (button.tag==304) {
        
        
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        
       userAudit = [user objectForKey:@"userAudit"];
        
//        if ([userAudit isEqualToString:@"Y"]) {
        
            handyListViewController* store=[[handyListViewController alloc]init];
            
            [self.navigationController pushViewController:store animated:YES];
//        }
//        

       
        
    }
}



//轮播视图
- (UIView *)_AutoScrollView {
    LinkType=[[NSMutableArray alloc]init];
    LinkCode=[[NSMutableArray alloc]init];
    ImageUrl1=[[NSMutableArray alloc]init];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setValue:Token forKey:@"tokenId"];
    
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:20 view:self.view];
    
    [HttpRequest requestData:@"System/SysAdverts" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                NSMutableArray*arr=[[NSMutableArray alloc]init];
                NSString*ResultInt=[severDataDict.dataDict objectForKey:@"ResultInt"];
                arr=[severDataDict.dataDict objectForKey:@"DataLine"];
                if (ResultInt.intValue==0) {
                    
                    if (arr.count<1) {
                        
                        
                        NSMutableArray *viewsArray = [NSMutableArray arrayWithCapacity:3];
                        NSArray *colorArray = @[@"banner",@"banner",@"banner"];
                        for (int i = 0; i < 3; ++i) {
                            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 160)];
                            imageView.image= [UIImage imageNamed:colorArray[i]];
                            
                            [viewsArray addObject:imageView];
                        }
                        
                        mainScorllView = [[ServiceView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 160) animationDuration:5];
                        
                        mainScorllView.backgroundColor = [[UIColor clearColor] colorWithAlphaComponent:0.1];
                        //
                        mainScorllView.fetchContentViewAtIndex = ^UIView *(NSInteger pageIndex){
                            
                            return viewsArray[pageIndex];
                        };
                        mainScorllView.totalPagesCount = ^NSInteger(void){
                            return [viewsArray count];
                        };
                        mainScorllView.TapActionBlock = ^(NSInteger pageIndex){
                            
                        };
                        [mainScroll addSubview:mainScorllView];
                    }else{
                        for (NSDictionary* dicc in arr )
                        {
                            
                            
                            [LinkCode addObject:[dicc objectForKey:@"adsiteName"]];
                            [ImageUrl1 addObject:[dicc objectForKey:@"imageUrl"]];
                            
                            
                        }
                        
                        NSArray* images=ImageUrl1;
                        commdity.InsurNum1=[NSString stringWithFormat:@"%ld",  [ImageUrl1 count]];
                        NSMutableArray *viewsArray = [NSMutableArray arrayWithCapacity:images.count];
                        
                        for (int i = 0; i < images.count; ++i) {
                            
                            UIButton* button=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 160)];
                            [button setTitle:[LinkCode objectAtIndex:i] forState:UIControlStateNormal];
                            [button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
                            button.tag=i;
                            
                            button.contentMode = UIViewContentModeScaleAspectFill;
                            [button setImageWithURL:[NSURL URLWithString:[images objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@""]];
                            
                            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 160)];
                            
                            [imageView addSubview:button];
                            
                            
                            [viewsArray addObject:imageView];
                            
                            
                            
                        }
                        mainScorllView = [[ServiceView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 160) animationDuration:5];
                        
                        mainScorllView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.1];
                        //
                        mainScorllView.fetchContentViewAtIndex = ^UIView *(NSInteger pageIndex){
                            
                            
                            return viewsArray[pageIndex];
                        };
                        mainScorllView.totalPagesCount = ^NSInteger(void){
                            return [viewsArray count];
                        };
                        mainScorllView.TapActionBlock = ^(NSInteger pageIndex){
                            
                            
                        };
                        
                        
                        [mainScroll addSubview:mainScorllView];
                        
                    }
                    
                }
                
            }
            
            
            else{
                [Global hideProgressHUDInternal:self.view];
                
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    
                    TheLoginViewController*detailViewController = [[TheLoginViewController alloc] init];
                    
                    [self.navigationController pushViewController:detailViewController animated:YES];
                    
                }
                
            }
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
            
            
            
        }
        
    }];
    
    return mainScorllView;
    
    
}



//上拉刷新
- (void)addheader
{
    
    //
    
    
    
    MJRefreshHeaderView* footer = [MJRefreshHeaderView header];
    footer.scrollView = _table;
    footer.beginRefreshingBlock = ^(MJRefreshBaseView* refreshView)
    {
        
        
        
        
//        [self _AutoScrollView];
        [self add];
        
        
        [self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:3.0f];
        NSLog(@"%@--->正在刷新", refreshView.class);
    };
    
}
- (void)doneWithView:(MJRefreshBaseView *)refreshView
{
    [_table reloadData];
    [refreshView endRefreshing];
}



- (void)setupCouponCommentView:(NSDictionary *)dic{
    
    NSMutableArray *commentArray = [dic objectForKey:@"DataLine"];
    allComment = [NSMutableArray array];
    for (int i = 0; i<commentArray.count; i++) {
        
        NSMutableDictionary *dataDic = commentArray[i];
        if (![dataDic isKindOfClass:[NSNull class]]){
            
            NSArray *commentPicArray = [dataDic objectForKey:@"tagList"];
            
            
            peisongBiaoqianModel *cModel = [[peisongBiaoqianModel alloc]init];
            
            cModel.userName = [dataDic objectForKey:@"intro"];
            cModel.title = [dataDic objectForKey:@"title"];
            cModel.distance =@"";
            cModel.headImageUrl = [dataDic objectForKey:@"imageUrl"];
            
            NSMutableArray *fakeCommentImagesSmall = [NSMutableArray array];
            NSMutableArray *fakeCommentImagesBig = [NSMutableArray array];
            for (NSDictionary *picDic in commentPicArray) {
                [fakeCommentImagesSmall addObject:[picDic objectForKey:@"content"]];
                [fakeCommentImagesBig addObject:[picDic objectForKey:@"content"]];
            }
            cModel.contentArr = fakeCommentImagesSmall;
            cModel.imagePicBig = fakeCommentImagesBig;
            [allComment addObject:cModel];
        }
    }
    
    [_table reloadData];
}



#pragma mark - TableView dataSource && delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return allComment.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    static NSString *identifier = @"biaoqianCell";
    
    peisongCell *cell = (peisongCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[NSBundle mainBundle] loadNibNamed:@"peisongCell" owner:self options:nil][0];
    }else{
        //cell中本来就有一个subview，如果是重用cell，则把cell中自己添加的subview清除掉，避免出现重叠问题
        //         [[cell.subviews objectAtIndex:1] removeFromSuperview];
        
    }
    
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    
    
    
    peisongBiaoqianModel *cModel = [[peisongBiaoqianModel alloc]init];
    
    cModel = allComment[indexPath.row];
    cell.comment = cModel;
    
    
    
    if (title.count !=indexPath.row+1) {
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 100-0.35, ScreenWidth-30, 0.35)];
        lineLabel1.backgroundColor=qianhuicolor;
        [cell.contentView addSubview:lineLabel1];
        
    }
    
    if (title.count ==indexPath.row+1) {
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(0, 100-0.35, ScreenWidth, 0.35)];
        lineLabel1.backgroundColor=qianhuicolor;
        [cell.contentView addSubview:lineLabel1];
        
    }
    
    
    
    
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return  100;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
        commdity.convenienceId=fid[indexPath.row];
        commdity.ctype=ctype[indexPath.row];
        ConvenienceDetailViewController *detailViewController = [[ConvenienceDetailViewController alloc] init];
        [self.navigationController pushViewController:detailViewController animated:YES];
    
    
    
}




- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}
@end